//
//  ViewController.m
//  UIPickerView
//
//  Created by Deepak Kumar on 31/07/09.
//

#import "RelationshipViewControlle.h"
#import "Request.h"
#import "AppDelegate.h"


@implementation RelationshipViewControlle
@synthesize mode;
@synthesize selectedItem;
@synthesize arrayNo;
@synthesize lblFrist,lblSecond;
@synthesize relationshipMode = _relationshipMode;

-(void) backPressed 
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)done
{        
    NSInteger relationIndex = [pickerView selectedRowInComponent:0];
    [[JGoUtility sharedCreateAccount] setValue:[NSString stringWithFormat:@"%d",relationIndex]
                                        forKey:@"status"];
    [self.navigationController popViewControllerAnimated:YES];    
}

-(void)initNavigationBar 
{    
    [self setLeftButtonImageActiveName:nil 
                          inactiveName:@"back-button" 
                                target:self 
                                action:@selector(backPressed)];
    [self setRightButtonImageActiveName:nil 
                           inactiveName:@"done-button"
                                 target:self 
                                 action:@selector(done)];
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"home_bg.png"]]]; 
}

- (void)viewDidLoad
{
	[super viewDidLoad];
    [self initNavigationBar];
    [self setTitle:@"Relationship"];
    
    self.lblSecond.textColor = [UIColor colorWithRed:0.573 green:0.573 blue:0.573 alpha:1];
    lblFrist.textColor = [UIColor colorWithRed:0. green:0.678 blue:0.941 alpha:1];
    arrayNo = [[NSMutableArray alloc] init];
    NSInteger statusIndex = [[[JGoUtility sharedCreateAccount] objectForKey:@"status"] integerValue];
    
	[arrayNo addObject:@"Happy Single"];
	[arrayNo addObject:@"Engaged"];
	[arrayNo addObject:@"Married"];
	[arrayNo addObject:@"Undisclosed"];
        
    [pickerView selectRow:statusIndex inComponent:0 animated:NO];
    [self.lblSecond setText:[arrayNo objectAtIndex:(statusIndex >= 0 && statusIndex < 4) ? statusIndex : 0]];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
	return 1;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    lblSecond.text=	[arrayNo objectAtIndex:row];
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
	return [arrayNo count];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)theView{
    
    UIView *pickerviewtemp=[[UIView alloc] initWithFrame:CGRectZero];
    
    UILabel *lbl=[[UILabel alloc] initWithFrame:CGRectMake(40, 0, 240, 30)];
    [lbl setBackgroundColor:[UIColor clearColor]];
    [lbl setText:[self.arrayNo objectAtIndex:row]];
    [lbl setFont:[UIFont boldSystemFontOfSize:20]];
    [pickerviewtemp addSubview:lbl];
   
    return pickerviewtemp;
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload
{
}

- (void)dealloc 
{
    [lblFrist release];
    [lblSecond release];
    [arrayNo release];
    [mode release];
    [super dealloc];
}


@end
